<!--

    Copyright (C) 2015 The Gravitee team (http://gravitee.io)

    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at

            http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.

-->
<div class="gv-page-container">
  <h1 *ngIf="!isEmpty">Scopes</h1>
  <div *ngIf="!isEmpty">
    <p>Scope is a mechanism in OAuth 2.0 to limit an application's access to a user's account. The access token issued to the application will be limited to the scopes granted.</p>
    <p>An application can request one or more scopes, this information is then presented to the user in the consent screen.</p>
    <ngx-datatable class="material"
                   [columnMode]="'flex'"
                   [headerHeight]="40"
                   [footerHeight]="40"
                   [rowHeight]="50"
                   [rows]='scopes'
                   [sorts]="[{prop: 'system', dir: 'desc'}, {prop: 'key', dir: 'asc'}]">
      <ngx-datatable-column name="Scopes" [flexGrow]="4" [cellClass]="'scope-name-cell'">
        <ng-template let-row="row" ngx-datatable-cell-template>
          <div class="scope-header" fxLayout="row">
            <div class="scope-icon">
              <mat-icon>playlist_add_check</mat-icon>
            </div>
            <div class="scope-information" fxLayout="column">
              <div fxLayout="row">
                <h3>{{row.key}}</h3>
                <mat-chip-list *ngIf="row.system"><mat-chip>system</mat-chip></mat-chip-list>
              </div>
              <small>{{row.description}}</small>
            </div>
          </div>
        </ng-template>
      </ngx-datatable-column>
      <ngx-datatable-column name="Discovery" [flexGrow]="1">
        <ng-template let-row="row" ngx-datatable-cell-template>
          <span>
            <mat-slide-toggle
              (change)="enableScopeDiscovery(row.id, $event)"
              [checked]="row.discovery"
              [disabled]="row.system || !canEdit">
            </mat-slide-toggle>
          </span>
        </ng-template>
      </ngx-datatable-column>
      <ngx-datatable-column name="Actions" [flexGrow]="1" *hasAnyPermission="['domain_scope_read', 'domain_scope_delete']">
        <ng-template let-row="row" ngx-datatable-cell-template>
          <div fxLayout="row" class="gv-table-cell-actions">
            <a mat-icon-button [routerLink]="[row.id]" *hasPermission="['domain_scope_read']"><mat-icon>settings</mat-icon></a>
            <button *ngIf="!row.system && canDelete" mat-icon-button (click)="delete(row.id, $event)"><mat-icon>delete</mat-icon></button>
          </div>
        </ng-template>
      </ngx-datatable-column>
    </ngx-datatable>
  </div>

  <app-emptystate *ngIf="isEmpty"
                  [message]="'Scopes will appear here'"
                  [subMessage]="'No data to display'"
                  [icon]="'donut_large'"></app-emptystate>

  <div *hasPermission="['domain_scope_create']" [ngClass]="{'gv-add-button': !isEmpty, 'gv-add-button-center': isEmpty}">
    <a mat-fab color="primary" [routerLink]="['new']">
      <mat-icon>add</mat-icon>
    </a>
  </div>
</div>
